package com.etc.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.etc.entity.Users;

//xx/api/listUser
@Controller
@RequestMapping("restapi")
public class UsersControllerRest {
	@Resource(name = "u")
	private Users u;

	// restapi/users
	//@ResponseBody 响应结果为 json格式的数据
	@RequestMapping(value = "users", method = RequestMethod.GET)
	@ResponseBody
	public Users getUser() {
		return u;
	}
	
	@RequestMapping(value = "users/{id}", method = RequestMethod.GET)
	@ResponseBody
	public Users getUserById(@PathVariable(value="id") int id) {
		System.out.println("rest id :"+id);		
		return u;
	}
	
	@RequestMapping(value = "users", method = RequestMethod.POST)
	@ResponseBody
	public void addUsers(@RequestBody Users user) {
		System.out.println("rest user :"+user);		
	}
	
	@RequestMapping(value = "users/{id}", method = RequestMethod.PUT)
	@ResponseBody
	public void updateUsers(@PathVariable(value="id") int id,@RequestBody Users user) {
		System.out.println("rest update user :"+user+",id :"+id);		
	}
	
	
	@RequestMapping(value = "users/{id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void delUsers(@PathVariable(value="id") int id) {
		System.out.println("rest delete id :"+id);		
	}
	
	
	
	
	
}
